#include <unistd.h>

#include <stdio.h>
#include <time.h>

#include "mod_monitor.h"
#include "func.h"
#include "test_lib.h"

static char* ignore_net = "enaphyt46i1,";
static char* ignore_disk = "/boot/efi,/boot,";

void use_list_monitor()
{
	char *p;
	FILE* log = fopen("./log.txt", "w");
	if (log == NULL) {
		printf("open log file failed\n");
		return;
	}


	NEW_LIST_NODE(list);
	ADD_MOD_LIST_2(pcie, PCIE, correction_value,   list, NULL);
	ADD_MOD_LIST(cpu,  CPU,    list, NULL);
	ADD_MOD_LIST(disk, DISK,   list, NULL);
	ADD_MOD_LIST(mem,  MEMORY, list, NULL);
	ADD_MOD_LIST(temp, TEMP,   list, NULL);
	ADD_MOD_LIST(net,  NET,    list, ignore_net);

	init_monitor_list_node(list);
	
	char buffer[8192];
	int n = 60*60*23*3;
	int k = 600;
	n = 10;
	int32_t size = 0;
        char buff[16];
	for (int i= 0;i < n; i++) {
		update_monitor_list_node_text(list, buffer, 8192);

		size = printf("%s\n", buffer);
		printf("len = %d\n", strlen(buffer));

		if (i % k == 0) {
			sprintf(buff, "%d", size);
                        p = record_process_rss(buff);
			fputs(p, log);
		}
		sleep(1);
	}
	fclose(log);

	clean_monitor_list_node(list);
	
	free(list);
	
}

USE_NODE_MONITOR_2(cpu,   CPU,    1, NULL, NULL)
USE_NODE_MONITOR_2(pcie , PCIE,   1, NULL, correction_value)
USE_NODE_MONITOR_2(disk,  DISK,   1, ignore_disk, NULL)
USE_NODE_MONITOR_2(mem,   MEMORY, 1, NULL, NULL)
USE_NODE_MONITOR_2(net,   NET,    1, ignore_net, NULL)
USE_NODE_MONITOR_2(temp,  TEMP,   1, NULL, NULL)

void use_node_monitor()
{
	//use_node_monitor_text_cpu();
	use_node_monitor_text_pcie();
	//use_node_monitor_text_disk();
	//use_node_monitor_text_mem();
	//use_node_monitor_text_net();
	//use_node_monitor_text_temp();
}


int main(int argc, char** argv)
{
	//use_list_monitor();
	use_node_monitor();
	//record_process_rss();
	//
	
}


